package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.CaseFile;
import com.ruoyi.web.ydz.service.ICaseFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 病例档案管理Controller
 * 
 * @author DRX
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/api/caseFile")
public class CaseFileController extends BaseController
{
    @Resource
    private ICaseFileService caseFileService;

    /**
     * 查询病例档案管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:file:list')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody CaseFile caseFile)
    {
        startPage();
        List<CaseFile> list = caseFileService.selectCaseFileList(caseFile);
        return getDataTable(list);
    }

    /**
     * 导出病例档案管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:file:export')")
    @Log(title = "病例档案管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseFile caseFile)
    {
        List<CaseFile> list = caseFileService.selectCaseFileList(caseFile);
        ExcelUtil<CaseFile> util = new ExcelUtil<CaseFile>(CaseFile.class);
        util.exportExcel(response, list, "病例档案管理数据");
    }

    /*
    * 导出病例档案PDF
    * */
    @PostMapping("/exportPDF")
    public void exportPDF(HttpServletRequest request, HttpServletResponse response, @RequestBody CaseFile caseFile){
        caseFileService.exportPDF(request,response,caseFile);
    }

    /**
     * 获取病例档案管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caseFileService.selectCaseFileById(id));
    }

    /**
     * 新增病例档案管理
     */
    @PreAuthorize("@ss.hasPermi('api:file:add')")
    @Log(title = "病例档案管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CaseFile caseFile)
    {
        return toAjax(caseFileService.insertCaseFile(caseFile));
    }

    /**
     * 修改病例档案管理
     */
    @PreAuthorize("@ss.hasPermi('api:file:edit')")
    @Log(title = "病例档案管理", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody CaseFile caseFile)
    {
        return toAjax(caseFileService.updateCaseFile(caseFile));
    }

    /**
     * 删除病例档案管理
     */
    @PreAuthorize("@ss.hasPermi('api:file:remove')")
    @Log(title = "病例档案管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caseFileService.deleteCaseFileByIds(ids));
    }
}
